/**
 * Created by admin on 2017/3/2.
 */
$(function () {
    $.ajax({
        url:'http://192.168.23.81:3000/api/getinlanddiscount',
        datatype:"json",
        success:function (data) {

            var arr = [];
            var group = data.result.length/4;
            for(var i = 1; i<=group;i++){
               arr.push({result: []});
                // console.log(arr);
            }
           $.each(data.result,function (i, v) {
                if(i<4){
                    arr[0].result.push(v);
                } else if(i<8){
                    arr[1].result.push(v);
                } else if(i<12){
                    arr[2].result.push(v);
                } else if(i<16){
                    arr[3].result.push(v);
                } else {
                    arr[4].result.push(v);
                }
           });
            // console.log(arr);
            var groups = 0;
            var html = template('template11', arr[groups]);
            // console.log(data);
            // 将当前点击的p标签对应的ul的内容设置为html
             //groups = 1;
            // html += template('template11', arr[groups]);
            // console.log(data);
            // 将当前点击的p标签对应的ul的内容设置为html
            $(".zhekou").html(html);

             $(window).scroll(function () {
                 var height =$(window).height()+$(window).scrollTop();
                 console.log($(document).scrollTop());
                 // var heiwen = $(document).height();
                 console.log($(window).height());
                 if(height==$(document).height()){
                     console.log($(document).height());
                     // console.log(groups);
                     groups++;
                     if(groups>=group){
                         return;
                     }
                     html = template('template11', arr[groups]);
                     // console.log(data);
                     // 将当前点击的p标签对应的ul的内容设置为html
                     $(".zhekou").append(html);
                 }
             })
        }
    })
});